<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateParkVegetationsTable extends Migration
{
    /**
     * Run the migrations.
     *园林植物管理
     *
     * @return void
     */
    public function up()
    {
        Schema::create('park_vegetations', function (Blueprint $table) {
            //字段定义
            $table->increments('id');
            $table->string('name',40)->comment('植被名称');
            $table->integer('landscaping_id')->unsigned()->comment('园林id')->nullable();
            $table->foreign('landscaping_id')->references('id')->on('landscapings')->onDelete('set null');
            $table->integer('vegetation_id')->unsigned()->comment('植被类型id')->nullable();
            $table->foreign('vegetation_id')->references('id')->on('vegetations')->onDelete('set null');
            $table->string('version',20)->comment('植被规模')->nullable();
            $table->integer('number')->unsigned()->comment('植被株数')->nullable();
            $table->string('unit')->comment('计量单位');
            $table->tinyInteger('level')->unsigned()->comment('养护等级');
            $table->string('sign',80)->comment('植被生长情况');
            $table->point('location')->comment('植被坐标')->nullable();
            $table->polygon('areas')->comment('植被区域')->nullable();
            $table->softDeletes();
            $table->timestamps();
        });
        
        //植物附件管理
        Schema::create('park_vegetation_files', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('v_id')->unsigned()->comment('植被id')->nullable();
            $table->foreign('v_id')->on('park_vegetations')->references('id')->onDelete('set null');
            $table->BigInteger('file_id')->unsigned()->comment('图片所属的文件信息')->nullable();
            $table->foreign('file_id')->on('file_upload')->references('id')->onDelete('set null');
            $table->timestamps();
        });

    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('park_vegetation_files');
        Schema::dropIfExists('park_vegetations');
    }
}
